package com.spotimage.eosps.test;


import java.io.InputStream;
import org.vast.ows.sps.DescribeTaskingResponse;
import org.vast.ows.sps.FeasibilityReport;
import org.vast.ows.sps.GetFeasibilityRequest;
import org.vast.ows.sps.GetFeasibilityResponse;
import org.vast.ows.sps.SPSUtils;
import org.vast.util.DateTime;
import org.vast.xml.DOMHelper;
import com.spotimage.eosps.EOReportHelper;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LinearRing;
import junit.framework.TestCase;


public class TutorialExamples extends TestCase
{
	protected SPSUtils utils = new SPSUtils();
	
	
	public void testReceivingGFRequest() throws Exception
	{
		InputStream inputStream = getClass().getResourceAsStream("GetFeasibility_OPT1_ASCII.xml");
		
		SPSUtils utils = new SPSUtils();
		
		// read describe tasking response for tasking parameters
		String respUrl = getClass().getResource("DescribeTaskingResponse_OPT1.xml").toString();
		DOMHelper dom = new DOMHelper(respUrl, false);
		DescribeTaskingResponse resp = (DescribeTaskingResponse)utils.readXMLResponse(dom, dom.getRootElement(), "SPS", "DescribeTaskingResponse");
		
		// read get feasibility request using these parameters
		dom = new DOMHelper(inputStream, false);
		GetFeasibilityRequest request = (GetFeasibilityRequest)utils.readParameterizedRequest(dom, dom.getRootElement(), resp.getTaskingParameters());
		
		
	}
	
	
	/*public void testSendingGFResponse() throws Exception
	{
		GetFeasibilityResponse gfResponse = new GetFeasibilityResponse();
		gfResponse.setVersion("2.0.0");
		gfResponse.setMaxResponseDelay(3600);
		gfResponse.getReport().setTitle("Automatic Feasibility");
		gfResponse.getReport().setTaskID("F001");
		gfResponse.getReport().setSensorID("urn:spot:sensors:SPOT5:HRG");
		gfResponse.getReport().setStatusCode(FeasibilityReport.FEASIBLE);
		gfResponse.getReport().touch();
		
		Element requestElt = utils.buildXMLResponse(dom, gfResponse);
		
		// instantiate helper
		DescribeTaskingResponse dtResp = readDescribeTaskingResponse(...);
		EOReportHelper helper = new EOReportHelper(gfResp, dtResp.getFeasibilityReportExtendedData());
		
		helper.setEstimatedCost(20000);
		
		// segments
		if (helper.hasSegments())
		{
			int numSegments = 5;		
			helper.setNumSegments(numSegments);		
			for (int s=0; s<numSegments; s++)
			{
				helper.loadSegment(s);
				
				helper.setID("SEG_00" + (s+1));
				
				helper.setPlatformID("urn:ogc:id:CEOS:platform:SPOT5");
				helper.setPlatformName("SPOT-5");
				helper.setInstrumentID("urn:ogc:id:CEOS:instrument:SPOT5:HRG1");
				helper.setInstrumentName("HRG1");
				helper.setInstrumentMode("PAN");
				
				// Time
				helper.setAcquisitionStart(new DateTime((2000+s) + "-05-22T10:45:12Z"));
				helper.setAcquisitionStop(new DateTime((2000+s) + "-06-22T10:45:20Z"));
				
				// Incidence
				helper.setElevationIncidence(13.5);
				helper.setAzimuthIncidence(102);
				
				// ROI
				GeometryFactory fac = new GeometryFactory();
				LinearRing outer = fac.createLinearRing(new Coordinate[]{
						new Coordinate(0+s, 0), new Coordinate(10+s, 0),
						new Coordinate(10+s, 10), new Coordinate(0+s, 10),
						new Coordinate(0+s, 0)});
				helper.setFootprint(fac.createPolygon(outer, null));
			}
		}
		
		// cells
		if (helper.hasGridCells())
		{
			int numCells = 3;
			helper.setNumGridCells(numCells);
			for (int s=0; s<numCells; s++)
			{
				helper.loadGridCell(s);
				
				helper.setID("CELL_00" + (s+1));
				
				// Success rate
				helper.setSuccessRate(80+s);
				
				// Estimated Success Date
				helper.setEstimatedSuccessDate(new DateTime((2000+s) + "-02-22T10:45:12Z"));

				// Next Attempt Date
				helper.setNextAttemptDate(new DateTime((2000+s) + "-01-22T10:45:12Z"));
				
				// ROI
				GeometryFactory fac = new GeometryFactory();
				LinearRing outer = fac.createLinearRing(new Coordinate[]{
						new Coordinate(0+s, 0), new Coordinate(10+s, 0),
						new Coordinate(10+s, 10), new Coordinate(0+s, 10),
						new Coordinate(0+s, 0)});
				helper.setFootprint(fac.createPolygon(outer, null));
			}
		}
		
	}*/
}
